<?php
class Town extends AppModel {
// Define the model and it's associations:
var $name = 'Town';
var $hasMany = array(
				'Pothole' => array(
					'className' => 'Pothole',
					'foreignKey' => 'town_ID',
					'dependent' => 'true'
					)
				);
var $belongsTo = array(
				'Metro' => array(
					'className' => 'Metro',
					'foreignKey' => 'metro_ID'
					)
				);
var $hasAndBelongsToMany = array(
							'Page' => array(
								'className' => 'Page',
								'joinTable' => 'objects_pages',
								'foreignKey' => 'object_ID',
								'associationForeignKey' => 'page_ID',
								'unique' => true
								)
							);

	/*
	// Ratings are a function of the number of positive ratings
	// divided by the total number of ratings.
	*/
	public function getComments($obj_id) {
		$comments = $this->find('all', array(
			'conditions' => array(
				'Comments.object_id' => $obj_id)));
		return $comments;
	}
	
	
	/*
	/	getTowns: get all towns within a metro ID
	/	string $metro_id: ID from the Towns table
	*/
	public function getTowns($metro_id) {
		$towns = $this->find('all', array(
			'conditions' => array(
				'Town.metro_id' => $metro_id)));
		return $towns;
	}
	
	
	/*
	/	fetchTownByName: gathers info about a town by name
	/	string $name: Name of the town
	*/
	public function fetchTownByName($name) {
		$town = $this->find('first', array(
			'conditions' => array(
				'Town.host_name' => $name)));
		return $town;
	}
	
	/*
	/	fetchTownInfoByName: fetch Town information by it's name
	/	string $town: town name
	*/
	public function fetchTownInfoByName($town) {
		$towninfo = $this->find('first', array(
			'conditions' => array(
				'Town.host_name' => $town)/*,
			'fields' => array(
				'Metro.ID')*/));
		return $towninfo;
	}
}
?>
